#pragma once
#include "stdafx.h"
#include "PreHeader.h"
#include "Resource.h"
#include "Texture.h"
#include "Animation.h"
//#include "AnimManager.h"
/*
Description of mesh:
	name: name of this mesh.
	vertex3d: Each mesh must has the vertex table, each vertex use three float value(x,y,z) to location this point in 3d coordinate system.
		vertex3d store the point directly(static) or indirectly(anim).
	index: Index is a optional element in mesh, start from 0, 
	tex: Tes is a optional element in mesh, must appearance with texture. use two float value(tu,tv)
	texture: see tex
	bone:
	usage: descript how to show this model. draw line or draw trangle
*/

class Resource;
class Texture;
//class AnimManager;

enum MeshUsage
{
	MESH_STATIC,
	MESH_ANIM,
	MESH_UNKNOWN
};
	
struct MeshStr
{
	MeshStr() {}
	~MeshStr()
	{
		if(verts!=NULL)
		{
			delete verts;
			verts=NULL;
		}
		if(weights!=NULL)
		{
			delete weights;
			weights=NULL;
		}
		if(vertices!=NULL)
		{
			delete vertices;
			vertices=NULL;
		}
		if(indexs!=NULL)
		{
			delete indexs;
			indexs=NULL;
		}
		if(texs!=NULL)
		{
			delete texs;
			texs=NULL;
		}
	}
	Verts* verts;
	Weights* weights;
	Vertices* vertices;
	Indexs* indexs;
	Texs* texs;
	Texture::sPtr texture;
};


class Mesh : public Resource
{
private:
	Mesh();
	
public:

	typedef boost::shared_ptr<Mesh> sPtr;
	typedef Vector<MeshStr*> SubMesh;
	typedef SubMesh::iterator SubMeshIter;
	typedef boost::shared_ptr< SubMesh > SubMeshPtr;
	
	Mesh(string,SubMeshPtr,MeshUsage);
	Mesh(string,SubMeshPtr,Anims*,MeshUsage);
	MeshUsage GetMeshUsage() const;
	void CalcAnim(const int);
	SubMeshPtr GetSubMeshs();
	~Mesh(void);
private:
	SubMeshPtr m_subMeshs;
	Animation::sPtr m_anim;
	MeshUsage m_usage;
	//AnimManager::sPtr m_animManager;
};

